/**游戏管理器，此类大部分代码无用都注释掉了，只管start方法进入业务和一些适配常量*/
class GameManager {
	private static _instance: GameManager;
	public static version: string = window["game_version"] ? window["game_version"] : "";
	public static game: Main;
	public static MIN_RATIO: number=NaN;
	public static MAX_RATIO: number=NaN;
	public static SCALE_MODE: string;
	public static DESIGN_WIDTH: number;
	public static DESIGN_HEIGHT: number;
	public static STAGE_WIDTH:number;
	public static STAGE_HEIGHT:number;	
	// public static STAGE_SCALE:number;
	// public static STAGE_OFFSET_X:number;
	// public static STAGE_OFFSET_Y:number;
	
	public static getInstance(): GameManager {
		if (GameManager._instance == null)new GameManager;
		return GameManager._instance;
	}
	/**debug模式会显示debug信息，例如游戏的角色碰撞盒子，且可以用键盘wsad(上下左右)自由控制行走*/
	public static debug: boolean = !window["release"];	
	// public gameScale: number = 1;
	// public maxRatio:number;
	// public minRatio:number;
	public startTime: number;
	public isGameOver:boolean;
	
	/**预留100个id位*/public uidCount: number = 100;
	private _isGameStart: boolean;
	// private _configMgr: ConfigManager;
	// private _stageWidth:number;
	// private _stageHeight:number;
	
	// public errorTexture:egret.Texture;	
	public static inited:boolean;
	
	// public cfgParser:ConfigParser;
	public globalLoad:{globalLoadPercent:Function,setPercent:Function,addLoadingUI:Function,removeLoadingUI:Function,hasLoading:boolean};
	
	public constructor() {
		let s = this;
		GameManager._instance = s;
		/**UI配置解析器*/
		// s.cfgParser = new ConfigParser;
		
		
		// s.maxRatio = s.minRatio = NaN;
		// let platForm:string = UserData.getInstance().getPlatform();
		// s.maxRatio = NaN;
		// s.minRatio = 4/3;
		s.globalLoad = window["globalLoad"]?window["globalLoad"]:{
			hasLoading:true,
			globalLoadPercent:function(cur,max,label){},
			setPercent:function(cur,max,label){},
			addLoadingUI:function():void{},
			removeLoadingUI:function():void{},
		};
	}	
	
	
	/**游戏初始化完成,进入游戏，游戏配置、资源已加载*/
	public gameInit(): void {
		var s = this;
		GameManager.inited = true;
		
		
	}

	

	public debugStart(): void {
		var s = this;
	}
	// private testFileData:string;
	public gameStart(): void {
		var s = this;		
		s._isGameStart = true;
		if(1)
		{
			GameManager.game.curModule = new GameManager.game._gameModule["Module"];
			if(SDK.addCall)
			{
				// GameManager.game.curModule.x = GameManager.STAGE_OFFSET_X;
				// GameManager.game.curModule.y = GameManager.STAGE_OFFSET_Y;
				GameManager.game.addToContainer(SDK.container?SDK.container:Laya.stage);
				SDK.addCall();				
				SDK.addCall = null;
			}
			// Laya.stage.addChild(new game_02.Module);	
			return;
		}
		
		// let img:Laya.Sprite = new Laya.Sprite;
		// // let m:Laya.Matrix = new Laya.Matrix;
		// let tex:Laya.Texture;
		// // m.tx = -300;		
		// tex = Main.instance.getRes(game_02.Conf.mapAlias + "B_0_0.png");
		// img.x = 300;
		// img.y = 300;		
		// img.texture = Main.instance.getRes(game_02.Conf.skillAlias + "slider.png");
		// Laya.stage.addChild(img);
		// game_02.SkinDictionary.init();
		// let hpTxt:ImageLabel = new ImageLabel();
						
		// 	hpTxt.setData(game_02.SkinDictionary.fillNum);
		// 	hpTxt.x = 300;
		// 	hpTxt.y = 300;
		// 	hpTxt.width = 400;
			
		// 	hpTxt.setForamt(0,new TextFormat(null,60));
		// 	hpTxt.align = "center";
		// 	hpTxt.text = "0123456789";
		// 	Laya.stage.addChild(hpTxt);
	}
	/**启动游戏的垃圾回收*/
	public gc():void
	{	
	}
	
	public gameEnd(win:boolean): void {
		var s = this;
		
		// s.dispatchEvent(new GYViewEvent(GYViewEvent.UPDATE_COMPLETE));
	}
	/**屏幕宽高比类型
	 * @return 1 偏方型 2 偏横版 3 横向很长 4 纵向
	*/
	public static getRatioType():number
	{let s = this;
		let stRatio:number=(9/16 + 3/4)/2;
		let ratio:number = Laya.Browser.clientHeight / Laya.Browser.clientWidth;		
		if(ratio > 1)
			return 4;
		if(ratio < 9/16)return 3;
		return stRatio < ratio?1:2;
	}



	public resize(w: number, h: number): void {
		var s = this;
		// console.log("a",s.stardardWidth / w);
		let sclX: number, sclY: number,scl:number;
		let ww:number,wh:number;
		GameManager.STAGE_WIDTH = w;
		GameManager.STAGE_HEIGHT = h;		
		let scaleX:number,scaleY:number,scale:number;
		scaleX = w / GameManager.DESIGN_WIDTH;
		scaleY = h / GameManager.DESIGN_HEIGHT;
		// GameManager.STAGE_SCALE = scale = Math.max(scaleX,scaleY);
		// GameManager.STAGE_OFFSET_X = w - GameManager.DESIGN_WIDTH * GameManager.STAGE_SCALE >> 1;
		// GameManager.STAGE_OFFSET_Y = h - GameManager.DESIGN_HEIGHT * GameManager.STAGE_SCALE >> 1;
		if(GameManager.game.curModule)
		{
			// GameManager.game.curModule.x = GameManager.STAGE_OFFSET_X;
			// GameManager.game.curModule.y = GameManager.STAGE_OFFSET_Y;
			GameManager.game.curModule.resize(w,h);
		}
			
	}
	private resetStardardSize():void
	{let s = this;		
		// if(s.getRatioType() == 1)
		// {
		// 	s.stardardWidth = 1440;
		// 	s.stardardHeight = 1080;
		// }
		// else
		// {
		// 	s.stardardWidth = 1920;
		// 	s.stardardHeight = 1080;
		// }		
	}
	public get destroyed():boolean
	{
		return this._destroyed;
	}
	private _destroyed:boolean = false;		

}